package com.mobile.collect.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mobile.collect.R;
import com.mobile.collect.beans.DevicePointInfo;

public class MyPointView extends RelativeLayout {
    public MyPointView(Context context) {
        super(context);
    }

    public MyPointView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyPointView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setPointInfo(DevicePointInfo info,boolean isSeleced) {
        TextView upTitleTv = findViewById(R.id.pointTitleTv);
        TextView downTitleTv = findViewById(R.id.downTitleTv);
        TextView leftTitleTv = findViewById(R.id.leftTitleTv);
        TextView rightTitleTv = findViewById(R.id.rightTitleTv);
        upTitleTv.setText(info.getLabelName());
        downTitleTv.setText(info.getLabelName());
        leftTitleTv.setText(info.getLabelName());
        rightTitleTv.setText(info.getLabelName());
        setDirection(info.getDirection());
        setBgType(info,isSeleced);
    }

    private void setSelect(){

    }



    public void setBgType(DevicePointInfo info,boolean isSeleced) {
        TextView upTitleTv = findViewById(R.id.pointTitleTv);
        TextView downTitleTv = findViewById(R.id.downTitleTv);
        TextView leftTitleTv = findViewById(R.id.leftTitleTv);
        TextView rightTitleTv = findViewById(R.id.rightTitleTv);
        int colorResId;
        if (isSeleced) {
            setBackgroundResource(R.color.green);
        }else{
            setBackgroundResource(R.color.touming);
        }
        if (info.getIsNewPoint()) {
            colorResId = Color.rgb(255, 0, 255);
        } else {
            if (info.getBgType() == 0) {
                colorResId = getContext().getResources().getColor(R.color.blackbgcolor);
            } else {
                colorResId = getContext().getResources().getColor(R.color.redbgcolor);
            }
        }
        upTitleTv.setBackgroundColor(colorResId);
        downTitleTv.setBackgroundColor(colorResId);
        leftTitleTv.setBackgroundColor(colorResId);
        rightTitleTv.setBackgroundColor(colorResId);
    }

    public void setDirection(int direction) {
        View uplayout = findViewById(R.id.upLayout);
        View downLayout = findViewById(R.id.downLayout);
        View leftLayout = findViewById(R.id.leftLayout);
        View rightLayout = findViewById(R.id.rightLayout);

        uplayout.setVisibility(View.GONE);
        downLayout.setVisibility(View.GONE);
        leftLayout.setVisibility(View.GONE);
        rightLayout.setVisibility(View.GONE);

        switch (direction) {
            case 0:
                rightLayout.setVisibility(View.VISIBLE);
                break;
            case 90:
                downLayout.setVisibility(View.VISIBLE);
                break;
            case 180:
                leftLayout.setVisibility(View.VISIBLE);
                break;
            case 270:
                uplayout.setVisibility(View.VISIBLE);
                break;
            default:
                uplayout.setVisibility(View.VISIBLE);
        }
    }


}
